﻿using System.Collections.Generic;
using System.Linq;
using Model;

namespace ReportBrowser.ViewModel
{
    internal class MessageContainerMemberViewModel : MemberViewModel
    {
        #region Lifecycle

        public MessageContainerMemberViewModel(Member model)
            : base(model) { }

        #endregion Lifecycle

        #region Properties

        public IEnumerable<MessageViewModel> Messages
        {
            get
            {
                return MessageViewModel.FindByMember(this.Model.TypeModuleAssemblyName,
                    this.Model.TypeModuleName, this.Model.TypeNamespaceName, this.Model.TypeName,
                    this.Model.Name);
            }
        }

        public double Weight
        {
            get
            {
                return this.Messages.Sum(mvm => mvm.Weight);
            }
        }

        #endregion Properties

        #region Methods

        public static bool HasMessages(Member model)
        {
            return MessageViewModel.IsAnyByMember(model.TypeModuleAssemblyName, model.TypeModuleName,
                model.TypeNamespaceName, model.TypeName, model.Name);
        }

        #endregion Methods
    }
}
